package com.example.housekeeping.service.impl;

import com.example.housekeeping.mapper.AdminMapper;
import com.example.housekeeping.mapper.BannerMapper;
import com.example.housekeeping.mapper.CommentMapper;
import com.example.housekeeping.pojo.dto.BannerAddNewDTO;
import com.example.housekeeping.pojo.dto.BannerUpdateDTO;
import com.example.housekeeping.pojo.dto.CommentAddNewDTO;
import com.example.housekeeping.pojo.dto.CommentUpdateDTO;
import com.example.housekeeping.pojo.entity.Banner;
import com.example.housekeeping.pojo.vo.BannerListItemVO;
import com.example.housekeeping.pojo.vo.BannerStandardVO;
import com.example.housekeeping.pojo.vo.CommentListItemVO;
import com.example.housekeeping.pojo.vo.CommentStandardVO;
import com.example.housekeeping.service.BannerService;
import com.example.housekeeping.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 轮播图(banner)管理服务实现类
 *
 * @author bob
 * @since 2023-03-20 19:36:07
 */
@Slf4j
@Service
public class BannerServiceImpl implements BannerService {
    @Autowired
    private BannerMapper bannerMapper;

    /**
     * 新增数据
     *
     * @param bannerAddNewDTO 实例对象
     * @return 实例对象
     */

    @Override
    public void addNew(BannerAddNewDTO bannerAddNewDTO) {
        Banner banner = new Banner();
        BeanUtils.copyProperties(bannerAddNewDTO,banner);
        bannerMapper.insert(banner);

    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */

    @Override
    public void deleteById(Long id) {
        bannerMapper.deleteById(id);
    }

    /**
     * 修改数据
     *
     * @param bannerUpdateDTO 实例对象
     * @return 实例对象
     */

    @Override
    public void updateById(Long id, BannerUpdateDTO bannerUpdateDTO) {

        Banner banner = new Banner();
        BeanUtils.copyProperties(bannerUpdateDTO,banner);
        banner.setId(id);
        bannerMapper.update(banner);
    }
    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */

    @Override
    public BannerStandardVO getStandardById(Long id) {
        BannerStandardVO bannerStandardVO = bannerMapper.selectById(id);
        return bannerStandardVO;

    }
    /**
     * 查询列表数据
     *
     * @return 实例对象
     */

    @Override
    public List<BannerListItemVO> list() {
        List<BannerListItemVO> list = bannerMapper.selectList();

        return list;
    }
}

